<template>
  <div id="menu">
    <el-menu
      class="el-menu-vertical-demo"
      background-color="#b3c0d1"
      text-color="#fff"
      active-text-color="#0f0"
      :unique-opened="true"
      :default-active="activeIndex"
    >
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>导航一</span>
        </template>
        <el-menu-item-group>
          <el-menu-item @click="activeMenu('/page1')" index="/page1">选项1</el-menu-item>
          <el-menu-item @click="activeMenu('/page2')" index="/page2">选项2</el-menu-item>
          <el-menu-item @click="activeMenu('/page3')" index="/page3">选项3</el-menu-item>
          <el-menu-item @click="activeMenu('/page4')" index="/page4">选项4</el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: "/page1",
    };
  },
  created() {
    if (sessionStorage.getItem("activeIndex")) {
      this.activeIndex = sessionStorage.getItem("activeIndex");
    }
  },
  mounted() {},
  methods: {
    activeMenu(path) {
      this.$router.push({ path: path, });
      this.activeIndex = path;
      sessionStorage.setItem("activeIndex", path);
    },
  },
};
</script>

<style scoped lang="scss">
#menu {
  height: 80vh;
}
</style>
